package stringjoinerdemo;

import java.util.StringJoiner;

public class StringJoiner1 {
    public static void main(String[] args) {
        //1.创建一个对象，用于指定中间的间隔符号
        StringJoiner sj1 = new StringJoiner("---");

        //2.添加元素
        sj1.add("aaa").add("bbb").add("ccc");
        System.out.println(sj1);

        //3.使用第二种构造方法创建对象
        StringJoiner sj2 = new StringJoiner(",","[","]");
        sj2.add("aaa").add("bbb").add("ccc");
        System.out.println(sj2);
        System.out.println("sj2的长度为:"+sj2.length());

        //4.将StringJoiner转化为字符串
        String str1 = sj1.toString();
        String str2 = sj2.toString();

        System.out.println("------------------------");
        System.out.println(str1);
        System.out.println(str2);
    }
}
